import 'package:flutter/material.dart';

class TextAndTypePage extends StatelessWidget {
  // 声明文本样式
  final textStyle = const TextStyle(
    fontFamily: 'OpenSans',
  );

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      body: Center(
        child: Padding(
          padding: const EdgeInsets.all(8.0),
          child: ListView(
            children: <Widget>[
              Text(
                'fontSize:设置字体大小',
                style: TextStyle(
                  fontSize: 28,
                ),
              ),
              Text(
                'color:设置字体颜色',
                style: TextStyle(fontSize: 20.0, color: Colors.blue),
              ),
              Text(
                'backgroundColor:设置背景颜色,',
                style: TextStyle(backgroundColor: Colors.blue, fontSize: 20.0),
              ),
              Text(
                'textScaleFactor:字体缩放比例',
                textScaleFactor: 2.0,
              ),
              Text(
                'height:字体高度的倍数',
                style: TextStyle(
                  height: 2.0,
                  fontSize: 20.0,
                ),
              ),
              Text(
                'fontFamily：设置字体',
                style: TextStyle(
                  fontSize: 28.0,
                  height: 1.2,
                  fontFamily: "OpenSans",
                ),
              ),
              Text(
                'textAlign:对齐位置',
                textAlign: TextAlign.center,
                textScaleFactor: 2.0,
              ),Text(
                'maxLines: 设置文本最多占据行数'*2,
                maxLines: 2,
                textScaleFactor: 1.8,
              ),

              Text(
                "overflow:设置文本超出样式" * 3,
                maxLines: 1,
                overflow: TextOverflow.ellipsis,
                textScaleFactor: 1.8,
              ),
              Text(
                'decoration：TextDecoration.underline设置下划线',
                style: TextStyle(
                  color: Colors.blue,
                  fontSize: 20.0,
                  height: 1.2,
                  decoration: TextDecoration.underline,
                  decorationStyle: TextDecorationStyle.dashed,
                ),
              ),
              Text(
                'decoration：TextDecoration.lineThrough设置废除线',
                style: TextStyle(
                  color: Colors.blue,
                  fontSize: 28.0,
                  height: 1.2,
                  decoration: TextDecoration.lineThrough,
                  decorationStyle: TextDecorationStyle.solid,
                ),
              ),
              DefaultTextStyle(
                //1.设置文本默认样式
                style: TextStyle(
                  color: Colors.red,
                  fontSize: 20.0,
                ),
                textAlign: TextAlign.left,
                child: Column(
                  mainAxisAlignment: MainAxisAlignment.center,
                  children: <Widget>[
                    Text("DefaultTextStyle：设置默认文本样式"),
                    Text("使用默认样式"),
                    Text(
                      "通过TextStyle自定义文本样式",
                      style: TextStyle(
                          inherit: false, //2.不继承默认样式
                          color: Colors.grey),
                    ),
                  ],
                ),
              ),
              Text(
                'textStyle使用声明的字体样式',
                textScaleFactor: 2,
                style: textStyle, //使用前面声明的文本样式
              ),
              Container(
                child: RichText(
                  text: TextSpan(
                    children: [
                      TextSpan(
                        text: '这是一个富文本,使用',
                        style: TextStyle(fontSize: 30, color: Colors.black),
                      ),
                      TextSpan(
                        text: 'RichText',
                        style: TextStyle(
                            fontSize: 30,
                            color: Colors.orange,
                            fontWeight: FontWeight.bold),
                      ),
                      TextSpan(
                          text: '和',
                          style: TextStyle(fontSize: 30, color: Colors.black)),
                      TextSpan(
                        text: 'TextSpan',
                        style: TextStyle(
                            fontSize: 30,
                            color: Colors.orange,
                            fontWeight: FontWeight.bold),
                      ),
                      TextSpan(
                        text: '实现',
                        style: TextStyle(fontSize: 30, color: Colors.black),
                      )
                    ],
                  ),
                ),
              )
            ],
          ),
        ),
      ),
    );
  }
}
